$(document).ready(function(){
		$("#check").keypress(function(){
			if(event.keyCode == 13){
				if($("#check").val() ){
					common();
					return	false;
				}
				alert("배송지를 입력하세요");
				return
			}
		});
		$("#btn").click(function(){
			if($("#check").val()){
				common();
				return
			}
			alert("배송지를 입력하세요");
			return
		});		
		function common(){
			$("#tbody").empty();
			$.ajax({
				url : "zipcode.do",
				type : "GET",
				dataType: "JSON",
				data : $("#f1").serialize(),
//				success:function(data){
//					alert(data[0].addressDetail);
//					if(data==""){
//						$("#tbody").html("검색 내용을 찾을수 있습니다. 다시 입력해주세요");
//					}else{
//						for(i=0; i<data.length;i++){
//							var str = data[i].addressDetail;
//				//			alert("<a href=javascript:showAddress('"+data[i].zipcode1+"','"+data[i].zipcode2+"','"+str+"');>");
//							$("#tbody").append(
//									$("<tr>").append($("<td align='left' colspan='2'>").html('<a href="javascript:showAddress('+"'"+data[i].zipcode1+"'"+','+"'"+data[i].zipcode2+"'"+','+"'"+data[i].addressDetail+"'"+');">'+data[i].zipcode1+" - "+ data[i].zipcode2+" "+data[i].addressDetail+'</a>')));
//						}
//					}
//				},
				success:function(jobj,msg,xhr){
					var list = jobj.list;
					$.each(list,function(idx,obj){
						$("#tbody").append(
								$("<tr>").append($("<td align='left' colspan='2'>").html('<a href="javascript:showAddress('+"'"+obj.zipcode1+"'"+','+"'"+obj.zipcode2+"'"+','+"'"+obj.sido+" "+obj.gugun+" "+obj.dong+"'"+');">'+obj.zipcode1+" - "+ obj.zipcode2+" "+obj.sido+" "+obj.gugun+" "+obj.dong+'</a>')));
					});
				},
				error:function(xhr){
					alert("오류가 났습니다."+xhr.status);
				}
			});
		}
	});
	function showAddress(zipcode1,zipcode2,addressDetail){
		opener.document.form1.zipcode1.value= zipcode1;
		opener.document.form1.zipcode2.value= zipcode2;
		opener.document.form1.address.value= addressDetail;
		window.close();
	}